package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("*")
                .allowCredentials(true);
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*System.out.println("配置文件已经生效");*/
        registry.addResourceHandler("/avatorImages/**").addResourceLocations("file:"+System.getProperty("user.dir")+"/src/main/resources/static/avatorImages/");
        registry.addResourceHandler("/song/**").addResourceLocations("file:"+System.getProperty("user.dir")+"/src/main/resources/static/song/");
        registry.addResourceHandler("/img/**").addResourceLocations("file:"+System.getProperty("user.dir")+"/src/main/resources/static/img/");
    }

}
